package com.kcht.np.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kcht.np.entity.SysDepartment;
import com.kcht.np.vo.dept.DeptCanModifyInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
  * <p>
  * 部门 Mapper
  * </p>
  *
  * @Package:        com.kcht.np.mp.mapper
  * @Description:    部门 Mapper
  * @Author:         liuqi
  * @CreateDate:     2020/3/31 11:46
 */

public interface SysDepartmentMapper extends BaseMapper<SysDepartment> {


    /**
     * 查询标识为{id}部门的子部门的数量
    */
    @Select("SELECT COUNT(*) FROM tb_sys_department WHERE parent_id = #{id}")
    int countChild(Long id);



    /**
     * 查询属于标识为{id}部门的用户数量
    */
    @Select("SELECT COUNT(*) FROM tb_sys_user WHERE dept_id = #{id}")
    int countUserRef(Long id);

    void updateDept(@Param("info") DeptCanModifyInfo info);

    @Select("select count(*) from tb_sys_department where name=#{deptName}")
    int countByDeptName(String deptName);
}
